// @ts-nocheck
/**
 * @Date: 2022-04-08 14:10:40
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-04-23 16:38:59
 * @FilePath: \weibo-api\middleware\validator.js
 * @Description: 模型验证中间件
 */
const { SuccessModel, ErrorModel } = require("../ResModel/index");
const userValidate = require("../validator/user");
const blogValidate = require("../validator/blog");
const userValidator = async (ctx, next) => {
  try {
    // console.log(ctx.request.body);
    userValidate(ctx.request.body);
    await next();
  } catch (error) {
    console.error(error);
    ctx.body = new ErrorModel(422, "数据格式校验错误!");
  }
};
const blogValidator = async (ctx, next) => {
  try {
    blogValidate(ctx.request.body);
    await next();
  } catch (error) {
    console.error(error);
    ctx.body = new ErrorModel(422, "数据格式校验错误!");
  }
};
module.exports = {
  userValidator,
  blogValidator,
};
